﻿#region using
using System;
using Microsoft.Xna.Framework;
#endregion

namespace AwesomeTanks.Sources.Tools
{
    /// <summary>
    /// Tools Class
    /// </summary>
	static class Extensions
    {
        #region Methods
        /// <summary>
        /// Vector to  angle.
        /// </summary>
        /// <param name="vector">The vector.</param>
        /// <returns></returns>
        public static float ToAngle(this Vector2 vector)
		{
			return (float)Math.Atan2(vector.Y, vector.X);
		}

        /// <summary>
        /// Scales a vector.
        /// </summary>
        /// <param name="vector">The vector.</param>
        /// <param name="length">The length.</param>
        /// <returns></returns>
		public static Vector2 ScaleTo(this Vector2 vector, float length)
		{
			return vector * (length / vector.Length());
		}

        /// <summary>
        /// Vector to Point.
        /// </summary>
        /// <param name="vector">The vector.</param>
        /// <returns></returns>
		public static Point ToPoint(this Vector2 vector)
		{
			return new Point((int)vector.X, (int)vector.Y);
		}

        /// <summary>
        /// Nexts float for Random.
        /// </summary>
        /// <param name="rand">The rand.</param>
        /// <param name="minValue">The minimum value.</param>
        /// <param name="maxValue">The maximum value.</param>
        /// <returns></returns>
		public static float NextFloat(this Random rand, float minValue, float maxValue)
		{
			return (float)rand.NextDouble() * (maxValue - minValue) + minValue;
		}

        /// <summary>
        /// Nexts vector2 for Random.
        /// </summary>
        /// <param name="rand">The rand.</param>
        /// <param name="minLength">The minimum length.</param>
        /// <param name="maxLength">The maximum length.</param>
        /// <returns></returns>
		public static Vector2 NextVector2(this Random rand, float minLength, float maxLength)
		{
			double theta = rand.NextDouble() * 2 * Math.PI;
			float length = rand.NextFloat(minLength, maxLength);
			return new Vector2(length * (float)Math.Cos(theta), length * (float)Math.Sin(theta));
        }
        #endregion
    }
}
